//
//  AY_DetailHeaderView.m
//  AiYue
//
//  Created by mac on 2023/10/24.
//

#import "AY_DetailHeaderView.h"

@interface AY_DetailHeaderView ()
@property (strong,nonatomic) UIImageView *bookImage;
@property (strong,nonatomic) UILabel *bookName;
@property (strong,nonatomic) UILabel *authorLabel;
@property (strong,nonatomic) UILabel *authorInfo;
@property (strong,nonatomic) UILabel *numberLabel;
@property (strong,nonatomic) UILabel *typeLabel;

@property (strong,nonatomic) UIView *scoreView;
@property (strong,nonatomic) UILabel *scoreLabel;
@property (strong,nonatomic) UILabel *score;
@property (strong,nonatomic) UILabel *numLabel;
@property (strong,nonatomic) UILabel *num;
@end

@implementation AY_DetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backImage = [AYTool createImageViewWithFrame:CGRectMake(0, 0, SCREEN_W, self.mj_h - YNUM(35)) andImage:nil andBg:nil andRadius:0 andAddSubView:self];
        
        UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        // 毛玻璃视图
        self.effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
        //添加到要有毛玻璃特效的控件中
        self.effectView.frame = self.backImage.bounds;
        [self addSubview:self.effectView];
        
        self.bookImage = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:YNUM(8) andAddSubView:self.effectView.contentView];
        [self.bookImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-YNUM(28));
            make.top.equalTo(self).offset(YNUM(20) + GK_STATUSBAR_NAVBAR_HEIGHT);
            make.width.mas_equalTo(YNUM(86));
            make.height.mas_equalTo(YNUM(114));
        }];
        
        self.bookName = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(18)] andLines:1 andRadius:0 andAddSubView:self.effectView.contentView];
        [self.bookName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(YNUM(28));
            make.top.equalTo(self.bookImage);
            make.right.equalTo(self.bookImage.mas_left).offset(-YNUM(15));
        }];
        
        self.authorLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"作者：" andTextColor:COLOR(@"#BFBFBF") andBgColor:nil andFont:YFont(13) andLines:1 andRadius:0 andAddSubView:self.effectView.contentView];
        [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bookName);
            make.top.equalTo(self.bookName.mas_bottom).offset(YNUM(10));
        }];
        
        self.authorInfo = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:YFont(13) andLines:1 andRadius:0 andAddSubView:self.effectView.contentView];
        [self.authorInfo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.authorLabel.mas_right);
            make.centerY.equalTo(self.authorLabel);
        }];
        
        self.numberLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#BFBFBF") andBgColor:nil andFont:YFont(13) andLines:1 andRadius:0 andAddSubView:self.effectView.contentView];
        [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bookName);
            make.top.equalTo(self.authorInfo.mas_bottom).offset(YNUM(10));
        }];
        
        self.typeLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:COLOR(@"#FEECD7") andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.effectView.contentView];
        self.typeLabel.textAlignment = NSTextAlignmentCenter;
        [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bookName);
            make.top.equalTo(self.numberLabel.mas_bottom).offset(YNUM(10));
            make.width.mas_equalTo(YNUM(64));
            make.height.mas_equalTo(YNUM(20));
        }];
        
        self.scoreView = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(8) andAddSubView:self];
        [self.scoreView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(YNUM(12));
            make.right.equalTo(self).offset(-YNUM(12));
            make.top.equalTo(self.typeLabel.mas_bottom).offset(YNUM(25));
            make.height.mas_equalTo(YNUM(80));
        }];
        
        self.score = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:YFont(22) andLines:1 andRadius:0 andAddSubView:self.scoreView];
        [self.score mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.scoreView).offset(YNUM(65));
            make.top.equalTo(self.scoreView).offset(YNUM(10));
        }];
        
        self.scoreLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"状态" andTextColor:COLOR(@"#646D75") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.scoreView];
        [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.score);
            make.top.equalTo(self.score.mas_bottom).offset(YNUM(3));
        }];
        
        self.num = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:YFont(22) andLines:1 andRadius:0 andAddSubView:self.scoreView];
        [self.num mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.scoreView).offset(-YNUM(65));
            make.top.equalTo(self.score);
        }];
        
        self.numLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"字数" andTextColor:COLOR(@"#646D75") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.scoreView];
        [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.num);
            make.top.equalTo(self.num.mas_bottom).offset(YNUM(3));
        }];
    }
    return self;
}

- (void)setBookModel:(BookModel *)bookModel {
    [self.bookImage sd_setImageWithURL:[NSURL URLWithString:bookModel.coverImg] placeholderImage:YImage(@"placeholderImage")];
    [self.backImage sd_setImageWithURL:[NSURL URLWithString:bookModel.coverImg] placeholderImage:YImage(@"placeholderImage")];
    self.bookName.text = bookModel.title;
    self.authorInfo.text = bookModel.author;
    self.numberLabel.text = [NSString stringWithFormat:@"%.01f万字 · %@",[bookModel.wordNum floatValue]/10000,[self getBookStatus:bookModel.status]];
    self.typeLabel.text = bookModel.categoryName;
    self.score.text = [self getBookStatus:bookModel.status];
    self.num.text = [NSString stringWithFormat:@"%.01f万字",[bookModel.wordNum floatValue]/10000];
}

- (NSString *)getBookStatus:(NSString *)status {
    switch (status.intValue) {
        case 1:
            return @"连载";
            break;
        case 2:
            return @"完结";
            break;
        case 3:
            return @"停更";
            break;
            
        default:
            return @"连载";
            break;
    }
}
@end
